package org.myorg.v3;

import java.util.Arrays;

import org.myorg.Gene;
/*
Formulation:

Minimize:
f(x) = 20+e-20*exp(-0.2*(sqrt((1/n)*sum(x(i)^2))-exp((1/n)*sum(cos(2*Pi*x(i)))

-32.768 <= x(i) <= 32.768.

global minimum

f(x) = 0
x(i) = 0, i=1:n
 */
public class FT33 extends Fc3 {

	public FT33(double[] mag) {
		data = Arrays.copyOf(mag, mag.length);
		mark = new boolean[data.length];
		for (boolean bm : mark) {
			bm = false;
		}
		count = 0;
/*		low = -32.378;
		high = 32.378;*/
		low = -10;
		high = 10;
		best = 23;
	}
	public FT33() {
		low = -32.378;
		high = 32.378;
//		low = -10;
//		high = 10;
//		best = 23;
	}
	



	public double fc(double[] tmp) {
		double s1 = 0;
		double s2 = 0;
		
		double n = tmp.length;
				
		for (int i = 0; i < n; i++ ) {
			s1 = s1 + tmp[i]*tmp[i];
			s2 = s2 + Math.cos(2*Math.PI*tmp[i]);
		}
		
		double y = 20 + Math.E-20*Math.exp(-0.2*(Math.sqrt(s1/n))) 
				- Math.exp(s2/n);
		double t1 = Math.sqrt(s1/n);
		double t2 = Math.exp(-0.2*s2);
		
		return y;
	}
	
//	@Override
//	public void caculate(Gene3 ps) {
//		// TODO Auto-generated method stub
//		/**
//		 * add your function here
//		 * for example: f(x)= sin(x) x [0, 3.14] 
//		 * set the genetic length is 1, so the mapping relation is
//		 * [0, 1] -> [0, 3.14]
//		 */
//		FGene3 person = (FGene3)ps;
//		person.setFitness(-org_value(ps));
//	}
//
//
//	@Override
//	public double org_value(Gene3 ps) {
//		FGene3 gene = (FGene3)ps;
//		//double x = (high - low)*gene.geneAt(0) + low;
//		//double tmp = (Math.PI + 100)*x/100 - 100;
//
//		
//		double[] tmp = new double[gene.getGene().length];
//		for (int i = 0; i < gene.getGene().length; i++ ) {
//			tmp[i] = (high - low)*gene.geneAt(i) + low;
//		}
//		
//		return fc(tmp);
//		
//	}
//	
//	
//	public double org_value(Gene3 ps, double begin, double all) {
//		FGene3 gene = (FGene3)ps;
//		//double x = (high - low)*gene.geneAt(0) + low;
//		//double tmp = (Math.PI + 100)*x/100 - 100;
//
//		double[] tmp = new double[gene.getGene().length];
//		
//		/*
//		 * 分割成右闭左开区间
//		 */
//		if ( begin != (all -1) && gene.geneAt(0) == 1d) {
//			gene.setGene(0, 0d);
//		}
//		
//		tmp[0] = ((high - low)/all)*gene.geneAt(0) + low + (high-low)*(begin/all);
//		
//		for (int i = 1; i < gene.getGene().length; i++ ) {
//			tmp[i] = (high - low)*gene.geneAt(i) + low;
//		}
//		
//		return fc(tmp);
//		
//	}
//
//	@Override
//	public void caculate(Gene3 ps, double begin, double all) {
//
//		FGene3 person = (FGene3)ps;
//		person.setFitness(-org_value(ps, begin, all));
//	
//	}
//	


}

